<script setup lang="ts">
import { ref } from "vue";
import useUserStore from "../store/userStore.ts";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import useSectionStore from "../store/sectionStore.ts";

const id = ref("");
const password = ref("");

const userStore = useUserStore();
const sectionStore = useSectionStore();
const router = useRouter();

const submitLogin = () => {
  userStore
    .login({
      id: id.value,
      password: password.value,
    })
    .then((res) => {
      console.log(res);
      if (res) router.push(sectionStore.routeURL);
    })
    .catch(() => {
      ElMessage.error("网络错误!!!");
    });
};
</script>

<template>
  <el-col :span="12" :offset="6">
    <h1 class="text-center text-4xl py-5">登录</h1>
    <el-form label-position="top" label-width="100" class="pt-5">
      <el-form-item label="学号:">
        <el-input :type="'text'" v-model="id" />
      </el-form-item>
      <el-form-item label="密码:">
        <el-input :type="'text'" show-password v-model="password" />
      </el-form-item>
      <el-button :type="'primary'" @click="submitLogin">登录</el-button>
    </el-form>
  </el-col>
</template>

<style scoped></style>
